class UserRole:
    VIEWER = 'viewer'
    OPERATOR = 'operator'
    ADMIN = 'admin'
    SUPER_ADMIN = 'super_admin'

class ImportPermission:
    FILL_EMPTY = 'fill_empty'
    OVERRIDE_EXISTING = 'override_existing'
    MODIFY_BASIC_INFO = 'modify_basic_info'

def has_import_permission(user, permission_type):
    """检查用户是否有指定的导入权限"""
    permission_map = {
        UserRole.VIEWER: [],
        UserRole.OPERATOR: [ImportPermission.FILL_EMPTY],
        UserRole.ADMIN: [ImportPermission.FILL_EMPTY, ImportPermission.OVERRIDE_EXISTING],
        UserRole.SUPER_ADMIN: [ImportPermission.FILL_EMPTY, ImportPermission.OVERRIDE_EXISTING, ImportPermission.MODIFY_BASIC_INFO]
    }
    
    user_permissions = permission_map.get(user.role, [])
    return permission_type in user_permissions

def can_override_field(user, table_name, field_name):
    """检查是否可以覆盖特定字段"""
    if table_name == 'students':
        # 基本信息表需要最高权限
        return user.role == UserRole.SUPER_ADMIN
    elif table_name in ['vision_records', 'intervention_records']:
        # 时序数据需要管理员权限
        return user.role in [UserRole.ADMIN, UserRole.SUPER_ADMIN]
    else:
        return False
